package logic

import (
	"context"
	"novel/models/mysql"

	"novel/novelrpc/internal/svc"
	"novel/novelrpc/novelrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type NovelAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewNovelAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NovelAddLogic {
	return &NovelAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *NovelAddLogic) NovelAdd(in *novelrpc.NovelAddRequest) (*novelrpc.NovelAddResponse, error) {
	// todo: add your logic here and delete this line
	novel := mysql.Novel{
		UserId:  int(in.UserId),
		Title:   in.Title,
		Profile: in.Profile,
		Types:   in.Types,
	}
	mysql.DB.Debug().Create(&novel)
	return &novelrpc.NovelAddResponse{
		NovelId: int64(novel.ID),
	}, nil
}
